//
//  ConfigManager.h
//  TodaysPlan
//
//  Created by 寺田 篤史 on 11/10/13.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "ConfigManager.h"

@implementation ConfigObject
@synthesize strDispTitle; 
@synthesize strKey;
@synthesize defaultValue;
@synthesize arraySelectTitle;
@synthesize arraySelectValue;

-(id) initWithKey:(NSString*)astrDispTitle 
		   strKey:(NSString*)astrKey 
	 defaultValue:(NSObject*)adefaultValue
{
	[super init];
	
	self.strDispTitle = [NSString stringWithString:astrDispTitle];
	self.strKey = [NSString stringWithString:astrKey];
	
	//values
	defaultValue = [adefaultValue copy];
	
	arraySelectTitle = nil;
	arraySelectValue = nil;
	
	return self;
}

-(void) dealloc
{
	[super dealloc];
	[strDispTitle release];
	[strKey release];
	
	//values
	[defaultValue release];
	
	[arraySelectTitle release];
	[arraySelectValue release];	
}
-(void) removeKey:(NSString *)key
{
 	NSUserDefaults *config = [NSUserDefaults standardUserDefaults];
    [config removeObjectForKey:key];
}
-(void) setValueInt:(NSInteger)aValue
{
	NSUserDefaults *config = [NSUserDefaults standardUserDefaults];
	[config setInteger:aValue forKey:strKey];
	[config synchronize];
}

-(void) setValueString:(NSString*)aValue
{
	NSUserDefaults *config = [NSUserDefaults standardUserDefaults];
	[config setObject:aValue forKey:strKey];
	[config synchronize];
}

-(void) setValueBool:(BOOL)aValue
{
	NSUserDefaults *config = [NSUserDefaults standardUserDefaults];
	[config setBool:aValue forKey:strKey];
	[config synchronize];
}

-(NSInteger) getValueInt
{
	NSInteger aValue =[[NSUserDefaults standardUserDefaults] integerForKey:strKey];
	return aValue;
}

-(NSString*) getValueString
{
	NSString *strValue = [[NSUserDefaults standardUserDefaults] stringForKey:strKey];
	if(nil==strValue)
	{
		strValue = (NSString*)defaultValue;
	}
	return strValue;
}

-(BOOL) getValueBool
{
	return [[NSUserDefaults standardUserDefaults] boolForKey:strKey];
}

-(void) addSelectData:(NSInteger)avalue strSelectTitle:(NSString*)strSelectTitle
{
	if (nil==arraySelectTitle)
	{
		arraySelectTitle = [NSMutableArray arrayWithObject:strSelectTitle];
	}
	else 
	{
		[arraySelectTitle addObject:strSelectTitle];
	}
	
	if (nil==arraySelectValue)
	{
		arraySelectValue = [NSMutableArray arrayWithObject:[NSNumber numberWithInt:avalue]];
	}
	else 
	{
		[arraySelectValue addObject:[NSNumber numberWithInt:avalue]];
	}
}


@end


@implementation ConfigManager

@synthesize cfgPkey;
@synthesize cfgTaskData;
@synthesize cfgMemoData;
@synthesize cfgPriority;
@synthesize cfgReminderDate;
@synthesize cfgReminder;
@synthesize cfgDone;
@synthesize cfgPriority_H;
@synthesize cfgPriority_M;
@synthesize cfgPriority_L;
@synthesize cfgAPNS;

- (id)init {
    if (self = [super init]) {

        cfgPkey = 
        [[ConfigObject alloc] initWithKey:@"PKEY" 
                                   strKey:@"cfgPkey"
                             defaultValue:nil];
        cfgTaskData = 
        [[ConfigObject alloc] initWithKey:@"タスク" 
                                   strKey:@"cfgTask"
                             defaultValue:nil];
    
        cfgMemoData = 
        [[ConfigObject alloc] initWithKey:@"メモ" 
							   strKey:@"cfgMemo"
						 defaultValue:nil];
        cfgPriority = 
        [[ConfigObject alloc] initWithKey:@"優先度" 
							   strKey:@"cfgPriority"
						 defaultValue:nil];
        cfgReminderDate = 
        [[ConfigObject alloc] initWithKey:@"通知日時" 
                                   strKey:@"cfgReminderDate"
                             defaultValue:nil];
        cfgReminder = 
        [[ConfigObject alloc] initWithKey:@"通知フラグ" 
                                   strKey:@"cfgReminder"
                             defaultValue:nil];
        cfgDone = 
        [[ConfigObject alloc] initWithKey:@"完了フラグ" 
                                   strKey:@"cfgDone"
                             defaultValue:nil];
        cfgPriority_H = 
        [[ConfigObject alloc] initWithKey:@"優先度高_配色" 
                                   strKey:@"cfgPriority_H"
                             defaultValue:nil];
        cfgPriority_M = 
        [[ConfigObject alloc] initWithKey:@"優先度中_配色" 
                                   strKey:@"cfgPriority_M"
                             defaultValue:nil];
        cfgPriority_L = 
        [[ConfigObject alloc] initWithKey:@"優先度低_配色" 
                                   strKey:@"cfgPriority_L"
                             defaultValue:nil];
        cfgAPNS = 
        [[ConfigObject alloc] initWithKey:@"アイコンバッジ" 
                                   strKey:@"cfgAPNS"
                             defaultValue:nil];
    }
    return self;
}

- (void)dealloc {
    [cfgPkey release];
    [cfgTaskData release];
    [cfgMemoData release];
    [cfgPriority release];
    [cfgReminderDate release];
    [cfgReminder release];    
    [cfgDone release];
    [cfgPriority_H release];
    [cfgPriority_M release];
    [cfgPriority_L release];
    [cfgAPNS release];
    [super dealloc];
}

@end
